package com.ampaiva.organizescreen.activity;

import android.graphics.Canvas;
import android.graphics.Point;

import com.ampaiva.organizescreen.model.Arrow;
import com.ampaiva.organizescreen.model.Connection;
import com.ampaiva.view.Geometry;

public class ConnectionDrawer {
	private final ArrowDrawer arrowDrawer = new ArrowDrawer();

	public void draw(Canvas canvas, Connection connection) {
		setPoints(connection.getArrow(),
		        Geometry.getNearestMiddlePoints(connection.getStart().getRegion().getBounds(), connection.getEnd().getRegion().getBounds()));
		arrowDrawer.draw(canvas, connection.getArrow());
	}

	private void setPoints(final Arrow arrow, Point[] nearestMiddlePoints) {
		arrow.setStart(nearestMiddlePoints[0]);
		arrow.setEnd(nearestMiddlePoints[1]);
	}

}
